local skel = fk.CreateSkill{
  name = "tea__suofu",
}
Fk:loadTranslationTable{
  ["tea__suofu"] = "索缚",
  [":tea__suofu"] = "每回合开始时，你可以横置或将势力变更至魏，然后摸两张牌。若如此做，本回合结束时，若你本回合未" ..
  "造成或受到伤害，你变更势力至吴，令当前回合角色视为对你使用冰【杀】。",
  ["#suofu_chained"] = "横置",
  ["#suofu_toWei"] = "变更势力至魏",
}
---@type TrigSkelSpec<TurnFunc>
local suofu = {
  mute = true,
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and (not player.chained or player.kingdom ~= "wei")
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local all_choices = { "#suofu_chained", "#suofu_toWei", "Cancel" }
    local choices = table.simpleClone(all_choices)
    if player.chained then
      table.removeOne(choices, "#suofu_chained")
    end
    if player.kingdom == "wei" then
      table.removeOne(choices, "#suofu_toWei")
    end
    if #choices > 0 then
      local choice = room:askToChoice(player, {
        choices = choices,
        all_choices = all_choices,
        skill_name = skel.name,
      })
      if choice == "#suofu_chained" or choice == "#suofu_toWei" then
        event:setCostData(self, { choice = choice })
        return true
      end
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local choice = event:getCostData(self).choice
    room:notifySkillInvoked(player, skel.name, "drawcard")
    if choice == "#suofu_chained" then
      player:broadcastSkillInvoke(skel.name, 1)
      player:setChainState(true)
    else
      player:broadcastSkillInvoke(skel.name, 2)
      room:changeKingdom(player, "wei", true)
    end
    if not player.dead then
      player:drawCards(2, skel.name)
    end
  end
}
---@type TrigSkelSpec<TurnFunc>
local suofu_delay = {
  mute = true,
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(skel.name) and player:usedSkillTimes(skel.name, Player.HistoryTurn) > 0 and not target.dead then
      local room = player.room
      local turn_event = room.logic:getCurrentEvent():findParent(GameEvent.Turn, true)
      if not turn_event then return end
      local suc = false
      room.logic:getActualDamageEvents(1, function (e)
        local dat = e.data
        if dat.damage > 0 and (dat.from == player or dat.to == player) then
          suc = true
          return true
        end
        return false
      end, Player.HistoryTurn, turn_event.id)
      return not suc
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if player.kingdom ~= "wu" then
      room:notifySkillInvoked(player, skel.name, "negative")
      player:broadcastSkillInvoke(skel.name, 3)
      room:changeKingdom(player, "wu", true)
    end
    local card = Fk:cloneCard("ice__slash")
    if not player.dead and not target.dead and target:canUseTo(card, player, { bypass_distances = true, bypass_times = true }) then
      card.skillName = skel.name
      local use = { ---@type UseCardDataSpec
        from = target,
        tos = { player },
        card = card,
        extraUse = true
      }
      player:broadcastSkillInvoke(skel.name, table.random{4, 5})
      room:useCard(use)
    end
  end
}
skel:addEffect(fk.TurnStart, suofu)
skel:addEffect(fk.TurnEnd, suofu_delay)
return skel